home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 15 / CU Amiga Magazine's Super CD-ROM 15 (1997)(EMAP Images)(GB)[!][issue 1997-10].iso / CUCD / Graphics / Ghostscript / source / gdevmem.h < prev    next >
Encoding:
C/C++ Source or Header  |  1997-03-15  |  9.1 KB  |  214 lines

  1. /* Copyright (C) 1991, 1995, 1996, 1997 Aladdin Enterprises.  All rights reserved.
  2.   
  3.   This file is part of Aladdin Ghostscript.
  4.   
  5.   Aladdin Ghostscript is distributed with NO WARRANTY OF ANY KIND.  No author
  6.   or distributor accepts any responsibility for the consequences of using it,
  7.   or for whether it serves any particular purpose or works at all, unless he
  8.   or she says so in writing.  Refer to the Aladdin Ghostscript Free Public
  9.   License (the "License") for full details.
  10.   
  11.   Every copy of Aladdin Ghostscript must include a copy of the License,
  12.   normally in a plain ASCII text file named PUBLIC.  The License grants you
  13.   the right to copy, modify and redistribute Aladdin Ghostscript, but only
  14.   under certain conditions described in the License.  Among other things, the
  15.   License requires that the copyright notice and this notice be preserved on
  16.   all copies.
  17. */
  18.  
  19. /* gdevmem.h */
  20. /* Private definitions for memory devices. */
  21.  
  22. #include "gsbitops.h"
  23.  
  24. /*
  25.    The representation for a "memory" device is simply a
  26.    contiguous bitmap stored in something like the PostScript
  27.    representation, i.e., each scan line (in left-to-right order), padded
  28.    to a multiple of bitmap_align_mod bytes, followed immediately by
  29.    the next one.
  30.  
  31.    The representation of strings in the interpreter limits
  32.    the size of a string to 64K-1 bytes, which means we can't simply use
  33.    a string for the contents of a memory device.
  34.    We get around this problem by making the client read out the
  35.    contents of a memory device bitmap in pieces.
  36.  
  37.    On 80x86 PCs running in 16-bit mode, there may be no way to
  38.    obtain a contiguous block of storage larger than 64K bytes,
  39.    which typically isn't big enough for a full-screen bitmap.
  40.    We take the following compromise position: if the PC is running in
  41.    native mode (pseudo-segmenting), we limit the bitmap to 64K;
  42.    if the PC is running in protected mode (e.g., under MS Windows),
  43.    we assume that blocks larger than 64K have sequential segment numbers,
  44.    and that the client arranges things so that an individual scan line,
  45.    the scan line pointer table, and any single call on a drawing routine
  46.    do not cross a segment boundary.
  47.  
  48.    Even though the scan lines are stored contiguously, we store a table
  49.    of their base addresses, because indexing into it is faster than
  50.    the multiplication that would otherwise be needed.
  51. */
  52.  
  53. /*
  54.  * Macros for scan line access.
  55.  * x_to_byte is different for each number of bits per pixel.
  56.  * Note that these macros depend on the definition of chunk:
  57.  * each procedure that uses the scanning macros should #define
  58.  * (not typedef) chunk as either uint or byte.
  59.  */
  60. #define declare_scan_ptr(ptr)    declare_scan_ptr_as(ptr, chunk *)
  61. #define declare_scan_ptr_as(ptr,ptype)\
  62.     register ptype ptr; uint draster
  63. #define setup_rect(ptr)   setup_rect_as(ptr, chunk *)
  64. #define setup_rect_as(ptr,ptype)\
  65.     draster = mdev->raster;\
  66.     ptr = (ptype)(scan_line_base(mdev, y) +\
  67.         (x_to_byte(x) & -chunk_align_bytes))
  68.  
  69. /* ------ Generic macros ------ */
  70.  
  71. /* Macro for declaring the essential device procedures. */
  72. dev_proc_get_initial_matrix(mem_get_initial_matrix);
  73. dev_proc_close_device(mem_close);
  74. #define declare_mem_map_procs(map_rgb_color, map_color_rgb)\
  75.   private dev_proc_map_rgb_color(map_rgb_color);\
  76.   private dev_proc_map_color_rgb(map_color_rgb)
  77. #define declare_mem_procs(copy_mono, copy_color, fill_rectangle)\
  78.   private dev_proc_copy_mono(copy_mono);\
  79.   private dev_proc_copy_color(copy_color);\
  80.   private dev_proc_fill_rectangle(fill_rectangle)
  81.  
  82. /* The following are used for all except planar or word-oriented devices. */
  83. dev_proc_open_device(mem_open);
  84. dev_proc_get_bits(mem_get_bits);
  85. /* The following are for word-oriented devices. */
  86. #if arch_is_big_endian
  87. #  define mem_word_get_bits mem_get_bits
  88. #else
  89. dev_proc_get_bits(mem_word_get_bits);
  90. #endif
  91. /* The following are used for the non-true-color devices. */
  92. dev_proc_map_rgb_color(mem_mapped_map_rgb_color);
  93. dev_proc_map_color_rgb(mem_mapped_map_color_rgb);
  94.  
  95. /*
  96.  * Macro for generating the device descriptor.
  97.  * Various compilers have problems with the obvious definition
  98.  * for max_value, namely:
  99.  *    (depth >= 8 ? 255 : (1 << depth) - 1)
  100.  * I tried changing (1 << depth) to (1 << (depth & 15)) to forestall bogus
  101.  * error messages about invalid shift counts, but the H-P compiler chokes
  102.  * on this.  Since the only values of depth we ever plan to support are
  103.  * powers of 2 (and 24), we just go ahead and enumerate them.
  104.  */
  105. #define max_value_gray(rgb_depth, gray_depth)\
  106.   (gray_depth ? (1 << gray_depth) - 1 : max_value_rgb(rgb_depth, 0))
  107. #define max_value_rgb(rgb_depth, gray_depth)\
  108.   (rgb_depth >= 8 ? 255 : rgb_depth == 4 ? 15 : rgb_depth == 2 ? 3 :\
  109.    rgb_depth == 1 ? 1 : (1 << gray_depth) - 1)
  110. #define mem_full_alpha_device(name, rgb_depth, gray_depth, open, map_rgb_color, map_color_rgb, copy_mono, copy_color, fill_rectangle, get_bits, map_cmyk_color, copy_alpha, strip_tile_rectangle, strip_copy_rop)\
  111. {    std_device_dci_body(gx_device_memory, 0, name,\
  112.       0, 0, 72, 72,\
  113.       (rgb_depth ? 3 : 0) + (gray_depth ? 1 : 0),    /* num_components */\
  114.       rgb_depth + gray_depth,    /* depth */\
  115.       max_value_gray(rgb_depth, gray_depth),    /* max_gray */\
  116.       max_value_rgb(rgb_depth, gray_depth),    /* max_color */\
  117.       max_value_gray(rgb_depth, gray_depth) + 1, /* dither_grays */\
  118.       max_value_rgb(rgb_depth, gray_depth) + 1 /* dither_colors */\
  119.     ),\
  120.     {    open,            /* differs */\
  121.         mem_get_initial_matrix,\
  122.         gx_default_sync_output,\
  123.         gx_default_output_page,\
  124.         mem_close,\
  125.         map_rgb_color,        /* differs */\
  126.         map_color_rgb,        /* differs */\
  127.         fill_rectangle,        /* differs */\
  128.         gx_default_tile_rectangle,\
  129.         copy_mono,        /* differs */\
  130.         copy_color,        /* differs */\
  131.         gx_default_draw_line,\
  132.         get_bits,        /* differs */\
  133.         gx_default_get_params,\
  134.         gx_default_put_params,\
  135.         map_cmyk_color,        /* differs */\
  136.         gx_forward_get_xfont_procs,\
  137.         gx_forward_get_xfont_device,\
  138.         gx_default_map_rgb_alpha_color,\
  139.         gx_forward_get_page_device,\
  140.         gx_default_get_alpha_bits,    /* default is no alpha */\
  141.         copy_alpha,        /* differs */\
  142.         gx_default_get_band,\
  143.         gx_default_copy_rop,\
  144.         gx_default_fill_path,\
  145.         gx_default_stroke_path,\
  146.         gx_default_fill_mask,\
  147.         gx_default_fill_trapezoid,\
  148.         gx_default_fill_parallelogram,\
  149.         gx_default_fill_triangle,\
  150.         gx_default_draw_thin_line,\
  151.         gx_default_begin_image,\
  152.         gx_default_image_data,\
  153.         gx_default_end_image,\
  154.         strip_tile_rectangle,    /* differs */\
  155.         strip_copy_rop,        /* differs */\
  156.         gx_default_get_clipping_box\
  157.     },\
  158.     0,            /* target */\
  159.     mem_device_init_private    /* see gxdevmem.h */\
  160. }
  161. #define mem_full_device(name, rgb_depth, gray_depth, open, map_rgb_color, map_color_rgb, copy_mono, copy_color, fill_rectangle, get_bits, map_cmyk_color, strip_tile_rectangle, strip_copy_rop)\
  162.   mem_full_alpha_device(name, rgb_depth, gray_depth, open, map_rgb_color,\
  163.             map_color_rgb, copy_mono, copy_color, fill_rectangle,\
  164.             get_bits, map_cmyk_color, gx_default_copy_alpha,\
  165.             strip_tile_rectangle, strip_copy_rop)
  166. #define mem_device(name, rgb_depth, gray_depth, map_rgb_color, map_color_rgb, copy_mono, copy_color, fill_rectangle, strip_copy_rop)\
  167.   mem_full_device(name, rgb_depth, gray_depth, mem_open, map_rgb_color,\
  168.           map_color_rgb, copy_mono, copy_color, fill_rectangle,\
  169.           mem_get_bits, gx_default_map_cmyk_color,\
  170.           gx_default_strip_tile_rectangle, strip_copy_rop)
  171.  
  172. /* Swap a rectangle of bytes, for converting between word- and */
  173. /* byte-oriented representation. */
  174. void mem_swap_byte_rect(P6(byte *, uint, int, int, int, bool));
  175.  
  176. /* Copy a rectangle of bytes from a source to a destination. */
  177. #define mem_copy_byte_rect(mdev, base, sourcex, sraster, x, y, w, h)\
  178.   bytes_copy_rectangle(scan_line_base(mdev, y) + x_to_byte(x),\
  179.                (mdev)->raster,\
  180.                base + x_to_byte(sourcex), sraster,\
  181.                x_to_byte(w), h)
  182.  
  183. /* Macro for casting gx_device argument */
  184. #define mdev ((gx_device_memory *)dev)
  185.  
  186. /* ------ Implementations ------ */
  187.  
  188. extern const gx_device_memory far_data mem_mono_device;
  189. extern const gx_device_memory far_data mem_mapped2_device;
  190. extern const gx_device_memory far_data mem_mapped4_device;
  191. extern const gx_device_memory far_data mem_mapped8_device;
  192. extern const gx_device_memory far_data mem_true16_device;
  193. extern const gx_device_memory far_data mem_true24_device;
  194. extern const gx_device_memory far_data mem_true32_device;
  195. extern const gx_device_memory far_data mem_planar_device;
  196. #if arch_is_big_endian
  197. #  define mem_mono_word_device mem_mono_device
  198. #  define mem_mapped2_word_device mem_mapped2_device
  199. #  define mem_mapped4_word_device mem_mapped4_device
  200. #  define mem_mapped8_word_device mem_mapped8_device
  201. #  define mem_true24_word_device mem_true24_device
  202. #  define mem_true32_word_device mem_true32_device
  203. #else
  204. extern const gx_device_memory far_data mem_mono_word_device;
  205. extern const gx_device_memory far_data mem_mapped2_word_device;
  206. extern const gx_device_memory far_data mem_mapped4_word_device;
  207. extern const gx_device_memory far_data mem_mapped8_word_device;
  208. extern const gx_device_memory far_data mem_true24_word_device;
  209. extern const gx_device_memory far_data mem_true32_word_device;
  210. #endif
  211. /* Provide standard palettes for 1-bit devices. */
  212. extern const gs_const_string mem_mono_b_w_palette;    /* black=1, white=0 */
  213. extern const gs_const_string mem_mono_w_b_palette;    /* black=0, white=1 */
  214.